package com.hoshiicloud.shxping.feign.hystrix;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.common.query.OmnipotentWrapper;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.saleorder.entity.Consultations;
import com.hoshiicloud.saleorder.entity.OrderInfo;
import com.hoshiicloud.saleorder.entity.OrderMain;
import com.hoshiicloud.saleorder.dto.OrderDTO;
import com.hoshiicloud.saleorder.entity.RefundOrder;
import com.hoshiicloud.saleorder.param.*;
import com.hoshiicloud.saleorder.param.OrderInfoQueryParam;
import com.hoshiicloud.saleorder.param.OrderInfoUpdateParam;
import com.hoshiicloud.saleorder.param.OrderMainQueryParam;
import com.hoshiicloud.saleorder.param.RefundOrderPayParam;
import com.hoshiicloud.saleorder.param.refund.RefundOrderListParam;
import com.hoshiicloud.saleorder.param.refund.RefundOrderPageParam;
import com.hoshiicloud.saleorder.vo.refund.RefundOrderVo;
import com.hoshiicloud.shxping.dto.PayResultDTO;
import com.hoshiicloud.shxping.feign.OrderFeignService;
import com.hoshiicloud.shxping.param.*;
import com.hoshiicloud.shxping.param.OrderMainStatusUpdateParam;
import com.hoshiicloud.shxping.param.OrderQueryParam;
import com.hoshiicloud.shxping.param.OrderSubmitParam;
import com.hoshiicloud.shxping.param.PayOrderParam;
import com.hoshiicloud.shxping.param.StoreOrderQueryParam;
import com.hoshiicloud.shxping.vo.CartDetailVO;
import com.hoshiicloud.shxping.vo.CartVO;
import com.hoshiicloud.shxping.vo.GoodsBrowseRecordDetailVO;
import com.hoshiicloud.shxping.vo.GoodsBrowseRecordVO;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author zhangshuhu
 * @version 1.0
 * @title: HystrixOrderFeignFallback
 * @description: 订单微服务FeignClient熔断器
 * @date 2019/6/10 0:43
 * @mail maiboyc@163.com
 */
@Slf4j
@Component
public class HystrixOrderFeignFallback implements FallbackFactory<OrderFeignService> {


    @Override
    @HystrixCommand
    public OrderFeignService create(Throwable throwable) {
        log.error("出现异常" + throwable.getMessage());
        return new OrderFeignService() {
            /**
             * 提交订单微服务异常处理
             * @param param
             * @return
             */
            @Override
            public Response submitOrder(OrderSubmitParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<PayResultDTO> payOrder(PayOrderParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 取消订单微服务异常处理
             * @param orderId
             * @return
             */
            @Override
            public Response cancelOrder(@Valid Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 批量取消订单微服务异常处理
             * @param orderIds
             * @return
             */
            @Override
            public Response batchCancelOrder(List<Long> orderIds) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 删除订单微服务异常处理
             * @param orderId
             * @return
             */
            @Override
            public Response deleteOrder(@Valid Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<Page<OrderDTO>> listOrder(OrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 获取所有订单列表
             * @param param 查询参数
             * @return Response<List<OrderDTO>>
             */
            @Override
            public Response<List<OrderDTO>> listAllOrders(OrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<OrderDTO> viewOrder(Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<OrderDTO> verificationOrder(Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<OrderDTO> verificationBatchOrder(OrderMainIdsUpdateParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<Page<OrderDTO>> listStoreOrder(StoreOrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<Page<OrderDTO>> listStoreOrderByDeliveryTime(StoreOrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<List<OrderMain>> listCanPickUpStoreOrder(StoreOrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<List<OrderMain>> listCanPickUpOrderWithTime(StoreOrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response updateOrderStatus(OrderMainStatusUpdateParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 查询商品购买记录
             * @param param 查询参数
             * @return Response<Map < String, Object>>
             */
            @Override
            public Response<Page<Map<String, Object>>> queryOrdersWithUserInfo(OrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 查询主订单信息
             * @param param 查询参数
             * @return Response<List < OrderMain>>
             */
            @Override
            public Response<List<OrderMain>> listOrderMainInfos(OrderMainQueryParam param) {
                return Response.failed("查询主订单信息异常: " + throwable.getMessage());
            }

            @Override
            public Response<OrderMain> getOrderMainById(Long id) {
                return Response.failed("根据主订单ID查询主订单信息,异常:" + throwable.getMessage());
            }

            /**
             * 查询子订单信息
             * @param param 查询参数
             * @return Response<List < OrderInfo>>
             */
            @Override
            public Response<List<OrderInfo>> listOrderInfos(OrderInfoQueryParam param) {
                return Response.failed("查询子订单信息异常: " + throwable.getMessage());
            }

            /**
             * 根据扩展spu主键组查询销售数量
             * @param spuIds 扩展spu主键组
             * @return Response<List < Map < String, Object>>>
             */
            @Override
            public Response<List<Map<String, Object>>> selectSalesCountBySpuIds(List<Long> spuIds, Integer status) {
                return Response.failed("根据扩展spu主键组查询销售数量异常: " + throwable.getMessage());
            }

            /**
             * 根据总店分组查询已售数量
             * @param status 订单状态
             * @return List<Map < String, Object>>
             */
            @Override
            public Response<List<Map<String, Object>>> selectSalesCountGroupByStorePid(Integer status) {
                return Response.failed("根据总店分组查询已售数量异常: " + throwable.getMessage());
            }

            /**
             * 按店铺分组获取店铺粉丝数和购买指数
             * @param status 订单状态
             * @return List<Map < String, Object>>
             */
            @Override
            public Response<List<Map<String, Object>>> getStoreFansAndBuyExponentGroupById(Integer status) {
                return Response.failed("按店铺分组获取店铺粉丝数和购买指数异常: " + throwable.getMessage());
            }

            @Override
            public Response<OrderInfo> getOrderInfoById(Long id) {
                return Response.failed("根据子订单ID查询子订单信息,异常:" + throwable.getMessage());
            }

            @Override
            public Response<Boolean> updateOrderInfoById(OrderInfoUpdateParam orderInfoParam) {
                return Response.failed("根据子订单ID修改子订单信息,异常:" + throwable.getMessage());
            }

            @Override
            public Response<List<OrderInfo>> getOrderInfoByIds(List<Long> ids) {
                return Response.failed("根据子订单ID集合获取子订单信息,异常:" + throwable.getMessage());
            }

            /**
             * 退款訂單
             * @param param 退款参数
             * @return
             */
            @Override
            public Response refundOrder(@RequestBody RefundOrderPayParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 新增购物车购物信息
             * @param param 加入购物车参数
             * @return Response
             */
            @Override
            public Response add(CartAddParam param) {
                return Response.failed("新增购物车购物信息失败");
            }

            /**
             * 修改购物车购物信息
             * @param param 更新购物车参数
             * @return Response
             */
            @Override
            public Response update(CartUpdateParam param) {
                return Response.failed("修改购物车购物信息失败");
            }

            /**
             * 更新购物车商品失效状态
             * @param userId 用户ID
             * @return Response
             */
            @Override
            public Response updateCartStatus(String userId) {
                return Response.failed("更新购物车商品失效状态失败");
            }

            /**
             * 删除购物车购物信息
             * @param id 购物车ID
             * @return Response
             */
            @Override
            public Response delete(String id) {
                return Response.failed("删除购物车购物信息失败");
            }

            /**
             * 批量删除购物车购物信息
             * @param ids 购物车IDS
             * @return Response
             */
            @Override
            public Response deleteByIds(List<Long> ids) {
                return Response.failed("批量删除购物车购物信息失败");
            }

            /**
             * 根据用户ID和店铺ID批量删除购物车购物信息
             * @param userId    用户ID
             * @param storeId   店铺ID
             * @return Response
             */
            @Override
            public Response deleteByUserIdAndStoreId(Long userId, Long storeId) {
                return Response.failed("根据用户ID和店铺ID批量删除购物车购物信息失败");
            }

            /**
             * 获取购物车购物信息详情
             * @param id 主键ID
             * @return Response<CartDetailVO>
             */
            @Override
            public Response<CartDetailVO> getDetail(String id) {
                return Response.failed("获取购物车购物信息详情失败");
            }

            /**
             * 获取购物车购物信息列表
             * @param param 查询参数
             * @return Response<List < CartVO>>
             */
            @Override
            public Response<List<CartVO>> getList(@Valid CartQueryParam param) {
                return Response.failed("获取购物车购物信息列表失败");
            }

            /**
             * 分页获取购物车购物信息列表
             * @param param 分页参数
             * @return Response<IPage < CartVO>>
             */
            @Override
            public Response<Page<CartVO>> getPage(CartQueryParam param) {
                return Response.failed("分页获取购物车购物信息列表失败");
            }

            /**
             * 新增商品浏览记录
             * @param param 新增参数
             * @return Response
             */
            @Override
            public Response add(@Valid GoodsBrowseRecordAddParam param) {
                return Response.failed("新增商品浏览记录失败");
            }

            /**
             * 获取商品浏览记录列表
             * @param param 查询参数
             * @return Response<List < GoodsBrowseRecordVO>>
             */
            @Override
            public Response<List<GoodsBrowseRecordVO>> getGoodsBrowseList(@Valid GoodsBrowseRecordQueryParam param) {
                return Response.failed("获取商品浏览记录列表失败");
            }

            /**
             * 获取商品浏览记录详情
             * @param id 浏览记录ID
             * @return Response<GoodsBrowseRecordDetailVO>
             */
            @Override
            public Response<GoodsBrowseRecordDetailVO> getGoodsBrowseDetail(String id) {
                return Response.failed("获取商品浏览记录详情失败");
            }

            /**
             * 根据spuIds查询商品浏览记录
             * @param spuIds 扩展spu主键集合
             * @return Response<List < Map < Long, Object>>>
             */
            @Override
            public Response<List<Map<String, Object>>> selectFocusCountBySpuIds(List<Long> spuIds) {
                return Response.failed("根据spuIds查询商品浏览记录异常: " + throwable.getMessage());
            }

            /**
             * 获取商品浏览记录根据基础spu分组
             * @return Response<List < Map < String, Object>>>
             */
            @Override
            public Response<List<Map<String, Object>>> selectFocusCountGroupByBaseSpuId() {
                return Response.failed("获取商品浏览记录根据基础spu分组异常: " + throwable.getMessage());
            }

            @Override
            public Response<RefundOrder> saveRefundOrder(RefundOrder entity) {
                return Response.failed("保存退款单失败: " + throwable.getMessage());
            }

            @Override
            public Response<Boolean> updataRefundOrderById(RefundOrder entity) {
                return Response.failed("更新退款单状态失败: " + throwable.getMessage());
            }

            @Override
            public Response<RefundOrder> getRefundOrderById(Long id) {
                return Response.failed("获取子订单信息失败: " + throwable.getMessage());
            }

            @Override
            public Response<List<RefundOrderVo>> listRefundOrder(RefundOrderListParam param) {
                return Response.failed("获取子订单下的退款单信息: " + throwable.getMessage());
            }

            @Override
            public Response<Page<RefundOrderVo>> pageRefundOrder(RefundOrderPageParam param) {
                return Response.failed("获取退款单分页信息失败: " + throwable.getMessage());
            }

            @Override
            public Response<List<RefundOrder>> omniRefundOrder(List<OmnipotentWrapper> wrappers) {
                return Response.failed("任意条件查询退款单失败: " + throwable.getMessage());
            }

            @Override
            public Response<Consultations> saveConsultations(Consultations entity) {
                return Response.failed("保存退款单协商历史失败: " + throwable.getMessage());
            }

            @Override
            public Response<Boolean> deletePhysicConsultations(Long refundId) {
                return Response.failed("删除退款单协商历史失败: " + throwable.getMessage());
            }

            @Override
            public Response<List<Consultations>> listConsultationsByRefundIds(List<Long> refundIds) {
                return Response.failed("根据退款单id集合获取协商历史失败: " + throwable.getMessage());
            }

            @Override
            public Response<List<Consultations>> listConsultationsByRefundId(Long refundId) {
                return Response.failed("根据退款单id获取协商历史失败: " + throwable.getMessage());
            }
        };
    }
}
